package com.qire.manhua.model.entity;

import com.qire.manhua.R;
import com.qire.common.model.enumeration.RewardType;

/**
 * 任务实体对象
 */
public class TaskEntity {

    public final int        id;
    public final String taskName;
    public final int        rewardNum;
    public final RewardType rewardType;
    public TaskState        state;

    public TaskEntity(int id, String taskName, int rewardNum, RewardType rewardType, int state){
        this.id         = id;
        this.taskName   = taskName;
        this.rewardNum  = rewardNum;
        this.rewardType = rewardType;
        this.state      = toTaskState(state);
    }

    /**
     * 奖励信息获取，会判定奖励类型从而组合奖励信息内容
     * @return
     *  奖励类型为VIP则返回 *天会员<br/>
     *  奖励类型为金豆则返回 *金豆<br/>
     */
    public String getRewardInfo(){
        return rewardType == RewardType.Vip ? rewardNum + "天会员" : rewardNum + "金豆";
    }

    /**
     * 领取奖励，该方法会修改任务状态为完成已领取
     */
    public void receiveReward(){
        state = TaskState.完成已领取;
    }

    /**
     * 是否未完成
     * @return 未完成返回true,否则false;
     */
    public boolean unfinished(){
        return state == TaskState.未完成;
    }

    /**
     * 是否可领取
     * @return 可领取返回true,否则false;
     */
    public boolean canReceive(){
        return state == TaskState.完成待领取;
    }

    private TaskState toTaskState(int state){
        switch (state){
            case 0 : return TaskState.完成待领取;
            case 1 : return TaskState.完成已领取;
            case 2 :
            default: return TaskState.未完成;
        }
    }

    public enum TaskState{

        完成待领取(0, "领奖励","#423300", R.drawable.app_task_center_button_yellow),
        完成已领取(1,"已完成", "#aeaeae",0),
        未完成(2,"去完成", "#282828", R.drawable.app_task_center_button_gray_border);

        public final int value;
        public final String text;
        public final String textColor;
        public final int    textBgRid;

        TaskState(int value, String text, String textColor, int textBgRid){
            this.value      = value;
            this.text       = text;
            this.textColor  = textColor;
            this.textBgRid  = textBgRid;
        }
    }
}
